//
//  ResultViewController.m
//  Account
//
//  Created by wanmeizty on 2016/11/29.
//  Copyright © 2016年 wanmeizty. All rights reserved.
//

#import "ResultViewController.h"

#import "AccountDetalView.h"

@interface ResultViewController ()

@property (nonatomic, strong) AccountDetalView * name1;
@property (nonatomic, strong) AccountDetalView * name2;
@property (nonatomic, strong) AccountDetalView * name3;
@property (nonatomic, strong) AccountDetalView * name4;
@property (nonatomic, strong) AccountDetalView * name5;

@end

@implementation ResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUIs];
    
    [self setDatas];
    // Do any additional setup after loading the view.
}

- (void)createUIs{
    
    CGFloat top = 10 * [XMScreenAdaptation adapterMultipleByWidth];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    CGFloat nameH = 80 * [XMScreenAdaptation adapterMultipleByWidth];
    
    UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, top, self.view.frame.size.width, nameH)];
    titleLabel.text = @"当前各人累计消费情况表";
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [self.rootScrollView addSubview:titleLabel];
    
    top += 40 * [XMScreenAdaptation adapterMultipleByWidth] + 10 * [XMScreenAdaptation adapterMultipleByWidth];
    
    AccountDetalView * name1 = [[AccountDetalView alloc] initWithFrame:CGRectMake(15 * [XMScreenAdaptation adapterMultipleByWidth], top, self.view.frame.size.width - 30 * [XMScreenAdaptation adapterMultipleByWidth], nameH)];
    [self.rootScrollView addSubview:name1];
    self.name1 = name1;
    
//    double fee1 = [[FMDBManager shareManager] getFeeFromTableWithName:@"张庭勇"];
    
//    [name1 setupDatasWithTitle:@"张庭勇" value:[NSString stringWithFormat:@"%.2f",fee1]];
    
    top += nameH;
    
    AccountDetalView * name2 = [[AccountDetalView alloc] initWithFrame:CGRectMake(15 * [XMScreenAdaptation adapterMultipleByWidth], top, self.view.frame.size.width - 30 * [XMScreenAdaptation adapterMultipleByWidth], nameH)];
    [self.rootScrollView addSubview:name2];
    self.name2 = name2;
    
//    double fee2 = [[FMDBManager shareManager] getFeeFromTableWithName:@"陈伟豪"];
    
//    [name2 setupDatasWithTitle:@"陈伟豪" value:[NSString stringWithFormat:@"%.2f",fee2]];
    
    top += nameH;
    
    AccountDetalView * name3 = [[AccountDetalView alloc] initWithFrame:CGRectMake(15 * [XMScreenAdaptation adapterMultipleByWidth], top, self.view.frame.size.width - 30 * [XMScreenAdaptation adapterMultipleByWidth], nameH)];
    [self.rootScrollView addSubview:name3];
    self.name3 = name3;
//    double fee3 = [[FMDBManager shareManager] getFeeFromTableWithName:@"王勇"];
    
//    [name3 setupDatasWithTitle:@"王勇" value:[NSString stringWithFormat:@"%.2f",fee3]];
    top += nameH;
    
    AccountDetalView * name4 = [[AccountDetalView alloc] initWithFrame:CGRectMake(15 * [XMScreenAdaptation adapterMultipleByWidth], top, self.view.frame.size.width - 30 * [XMScreenAdaptation adapterMultipleByWidth], nameH)];
    [self.rootScrollView addSubview:name4];
    self.name4 = name4;
//    double fee4 = [[FMDBManager shareManager] getFeeFromTableWithName:@"张帆"];
    
//    [name4 setupDatasWithTitle:@"张帆" value:[NSString stringWithFormat:@"%.2f",fee4]];
    top += nameH;
    
    AccountDetalView * name5 = [[AccountDetalView alloc] initWithFrame:CGRectMake(15 * [XMScreenAdaptation adapterMultipleByWidth], top, self.view.frame.size.width - 30 * [XMScreenAdaptation adapterMultipleByWidth], nameH)];
    [self.rootScrollView addSubview:name5];
    self.name5 = name5;
//    double fee5 = [[FMDBManager shareManager] getFeeFromTableWithName:@"周建"];
    
//    [name5 setupDatasWithTitle:@"周建" value:[NSString stringWithFormat:@"%.2f",fee5]];
    
}

- (void)setDatas{
    
    NSDictionary * dict = [[FMDBManager shareManager] getEveryOneFeestringFromTable];
    
    double ztyfee = [[dict valueForKey:@"张庭勇"] doubleValue];
    
    double cwhfee = [[dict valueForKey:@"陈伟豪"] doubleValue];
    
    double wyfee = [[dict valueForKey:@"王勇"] doubleValue];
    
    double zffee = [[dict valueForKey:@"张帆"] doubleValue];
    
    double zjfee = [[dict valueForKey:@"周建"] doubleValue];
    
    double ztytotalfee = [[dict valueForKey:@"zty"] doubleValue];
    
    double cwhtotalfee = [[dict valueForKey:@"cwh"] doubleValue];
    
    double wytotalfee = [[dict valueForKey:@"wy"] doubleValue];
    
    double zftotalfee = [[dict valueForKey:@"zf"] doubleValue];
    
    double zjtotalfee = [[dict valueForKey:@"zj"] doubleValue];
    
    
    
    double ztypayfee = ztyfee - ztytotalfee;
    
    double cwhpayfee = cwhfee - cwhtotalfee ;
    
    double wypayfee = wyfee - wytotalfee ;
    
    double zfpayfee = zffee - zftotalfee;
    
    double zjpayfee = zjfee - zjtotalfee ;
    
    
    [self.name1 setupDatasWithTitle:@"张庭勇" value:[NSString stringWithFormat:@"待付费用：%.2f元",ztypayfee] andDesc:[NSString stringWithFormat:@"当前消费：%.2f元,当前已支付：%.2f元",ztyfee,ztytotalfee]];
    
    [self.name2 setupDatasWithTitle:@"陈伟豪" value:[NSString stringWithFormat:@"待付费用：%.2f元",cwhpayfee] andDesc:[NSString stringWithFormat:@"当前消费：%.2f元,当前已支付：%.2f元",cwhfee,cwhtotalfee]];

    [self.name3 setupDatasWithTitle:@"王勇" value:[NSString stringWithFormat:@"待付费用：%.2f元",wypayfee] andDesc:[NSString stringWithFormat:@"当前消费：%.2f元,当前已支付：%.2f元",wyfee,wytotalfee]];
    

    [self.name4 setupDatasWithTitle:@"张帆" value:[NSString stringWithFormat:@"待付费用：%.2f元",zfpayfee] andDesc:[NSString stringWithFormat:@"当前消费：%.2f元,当前已支付：%.2f元",zffee,zftotalfee]];
    
    [self.name5 setupDatasWithTitle:@"周建" value:[NSString stringWithFormat:@"待付费用：%.2f元",zjpayfee] andDesc:[NSString stringWithFormat:@"当前消费：%.2f元,当前已支付：%.2f元",zjfee,zjtotalfee]];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
